package com.jiashihui.encrypt.auto;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.jiashihui.encrypt.advice.EncryptRequestBodyAdvice;
import com.jiashihui.encrypt.advice.EncryptResponseBodyAdvice;

/**
 * 加解密自动配置
 *
 * @Configuration可理解为用spring的时候xml里面的<beans>标签
 * @Bean可理解为用spring的时候xml里面的<bean>标签
 * @EnableConfigurationProperties(EncryptProperties.class)来明确指定需要用哪个实体类来装载配置信息
 *
 * 1、@Service用于标注业务层组件
 * 2、@Controller用于标注控制层组件(如struts中的action)
 * 3、@Repository用于标注数据访问组件，即DAO组件.
 * 4、@Component泛指组件，当组件不好归类的时候，我们可以使用这个注解进行标注。
 */
@Configuration
@Component
@EnableAutoConfiguration
@EnableConfigurationProperties(EncryptProperties.class)
public class EncryptAutoConfiguration {

	/**
	 * 配置请求解密
	 * @return
	 */
	@Bean
	public EncryptResponseBodyAdvice encryptResponseBodyAdvice() {
		return new EncryptResponseBodyAdvice();
	}
	
	/**
	 * 配置请求加密
	 * @return
	 */
	@Bean
	public EncryptRequestBodyAdvice encryptRequestBodyAdvice() {
		return new EncryptRequestBodyAdvice();
	}
	
}
